package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.common.constant.ServiceOfferConsts;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.manager.api.IOperateSceneInstService;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInstFunc;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.data.CustAttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.util.ContextUtil;
import com.ztesoft.bss.common.util.SpringUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 折扣=合同价格/标准价格*100%
 * yangguobin
 */
public class LocalBigDataFeeAttrHandler  extends AbstractAttrHandler<KiteProdInstFunc, CustAttrData> {
    @Autowired
    IOperateSceneInstService operateSceneInstService;
    @Autowired
    private IQuerySceneInstService querySceneInstService;
    @Override
    public void after(KiteAttr attr, KiteProdInstFunc inst, CustAttrData data) {
        super.after(attr, inst, data);
        KiteInst kiteInst = querySceneInstService
            .getKiteInst(data.getCustId(), InstType.PROD_INST, inst.getAccProdInstId());
        KiteAttr attr3 = kiteInst.getAttr("200001077");//折扣(%)
        if (KiteObjectUtils.isEmpty(kiteInst)) {
            return;
        }
        KiteAttr attr1 = kiteInst.getAttr("200001052");//合同价格
        KiteAttr attr2 = kiteInst.getAttr("200001718");//标准价格
        if (!KiteObjectUtils.isEmpty(attr1.getValue())&&!KiteObjectUtils.isEmpty(attr2.getValue())) { //B2B2C
            Integer value1= Integer.parseInt(attr1.getValue());
            Integer value2=Integer.parseInt(attr2.getValue());
            String value=value1/value2+"%";
            attr3.setValue(value);
        }
        operateSceneInstService.setAttr(data.getSceneInstId(), inst.getInstType(), inst.getInstId(), attr3);
    }
}
